package customerEnter.Frame.oss;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.SAXException;

import customerEnter.Frame.Utils.javaReflexClass;

/**
 * 讀取oss配置文件
 * 
 * 类名称：OSSxml 类描述： 创建人：dy 创建时间：2016-6-1 下午5:49:04
 * 
 */
public class OSSxml {

	public static void InOss() throws SAXException, IOException, Exception {
		Object cla = OSSUseTransmission.class.newInstance();
		OSSXMLAssignment("oss.xml", cla);
	}

	/**
	 * @param xmlName
	 *            xml文件路徑
	 * @param Node
	 *            子節點名稱
	 * @param NamedItem
	 *            節點屬性
	 * @param NamedItemValue
	 *            節點屬性的值
	 * @throws Exception
	 * @throws IOException
	 * @throws SAXException
	 * 
	 */
	@SuppressWarnings({ "rawtypes" })
	private static void OSSXMLAssignment(String xmlName, Object cla) throws SAXException, IOException, Exception {
		File f = new File(new OSSxml().getClass().getResource("/" + xmlName).getPath());

		SAXReader reader = new SAXReader();
		Document document = reader.read(f);
		Element root = document.getRootElement();
		Iterator it = root.elementIterator();
		while (it.hasNext()) {
			Element element = (Element) it.next();
			// 未知属性名称情况下
			Iterator attrIt = element.attributeIterator();
			boolean b = false;
			while (attrIt.hasNext()) {
				Attribute a = (Attribute) attrIt.next();
				if ("false".equals(a.getValue())) {
					b = false;
				} else {
					b = true;
				}
				break;
			}
			if (b) {
				Iterator eleIt = element.elementIterator();
				while (eleIt.hasNext()) {
					Element e = (Element) eleIt.next();
					javaReflexClass.IsAssignment(cla, e.getName(), e.getText().trim());
				}
			}
		}
	}

}
